<?php
	if(!defined('__HIGHSCORE_PHP__'))
	{
		define('__HIGHSCORE_PHP__', true);
		
		include("IComparable.php");
		include("IXMLable.php");
		
		/**
		 * @class Represents a highscore, with name, score, date and time of the highscore.
		 * Implements IComparable and IXMLable
		 */
		class Highscore implements IComparable, IXMLable
		{
			/**
			 * @var The level of this highscore
			 */
			private $m_Level;
			/**
			 * @var The score of this highscore
			 */
			private $m_Score;
			/**
			 * @var The date this highscore was achieved
			 */
			private $m_Date;
			/**
			 * @var The difficulty level at chich this highscore was taken
			 */
			private $m_Difficulty;
			/**
			 * @var The time this highscore was achieved
			 */
			private $m_Time;
			/**
			 * @var The name of this highscore keeper
			 */
			private $m_Name;
			
			/**
			 * @method Constructor, initializes members
			 * 
			 * @param $name The name to set (string)
			 * @param $level The level to set (string)
			 * @param $score The score to set (string)
			 * @param $date The date to set (string)
			 * @param $time The time to set (string)
			 */
			function __construct($name, $level, $score, $date, $difficulty, $time)
			{
				$this->m_Level = $level;
				$this->m_Score = $score;
				$this->m_Date = $date;
				$this->m_Difficulty = $difficulty;
				$this->m_Time = $time;
				$this->m_Name = $name;
			}
			
			/**
			 * @implementation Compares this instance to another instance of this class
			 * 
			 * @param $that The instance to compare this instance to (IComparable)
			 * @return 0 if the two instances are exactly alike, a negative number if this instance
			 * is smaller than the one it's being compared to, and a positive number if this
			 * instance is bigger than the one it's being compared to
			 */
			function compareTo($that)
			{
				$result = 0;
				
				if(($that instanceof Highscore) && ($that->m_Difficulty == $this->m_Difficulty))
				{
					$result = $this->m_Score - $that->m_Score;
					
					if($result == 0)
					{
						$result = $that->m_Level - $this->m_Level;
					}
					
					if($result == 0)
					{
						$result = strcmp($that->m_Date, $this->m_Date);
					}
					
					if($result == 0)
					{
						$result = strcmp($that->m_Time, $this->m_Time);
					}
				}
				
				return $result;
			}
			
			/**
			 * @implementation Converts this class to an XML representation
			 * 
			 * @return A string containing this classes XML representation
			 */
			function toXML()
			{
				$xmlString = "<highscore>\n<name>";
				$xmlString .= $this->m_Name;
				$xmlString .= "</name>\n<level>";
				$xmlString .= $this->m_Level;
				$xmlString .= "</level>\n<score>";
				$xmlString .= $this->m_Score;
				$xmlString .= "</score>\n<date>";
				$xmlString .= $this->m_Date;
				$xmlString .= "</date>\n<time>";
				$xmlString .= $this->m_Time;
				$xmlString .= "</time>\n</highscore>\n\n";
				
				return $xmlString;
			}
			
			/**
			 * @override Returns a string representation of this class
			 * 
			 * @return A string representation of this class
			 */
			function __toString()
			{
				$str = $this->m_Name;
				$str .= "\n";
				$str .= $this->m_Level;
				$str .= "\n";
				$str .= $this->m_Score;
				$str .= "\n";
				$str .= $this->m_Date;
				$str .= "\n";
				$str .= $this->m_Time;
				$str .= "\n";
				
				return $str;
			}
			
			function getName()
			{
				return $this->m_Name;
			}
			
			function getLevel()
			{
				return $this->m_Level;
			}
			
			function getScore()
			{
				return $this->m_Score;
			}
			
			function getDate()
			{
				return $this->m_Date;
			}
			
			function getTime()
			{
				return $this->m_Time;
			}
			
			function getDifficulty()
			{
				return $this->m_Difficulty;
			}
		}
	}
?>
